<%@LANGUAGE="VBSCRIPT"%> 
<!--#include file="Connections/labdict.asp" -->
<%
' *** Edit Operations: declare variables

MM_editAction = CStr(Request("URL"))
If (Request.QueryString <> "") Then
  MM_editAction = MM_editAction & "?" & Request.QueryString
End If

' boolean to abort record edit
MM_abortEdit = false

' query string to execute
MM_editQuery = ""
%>
<%
' *** Update Record: set variables

If (CStr(Request("MM_update")) <> "" And CStr(Request("MM_recordId")) <> "") Then

  MM_editConnection = MM_labdict_STRING
  MM_editTable = "LABDICT_DOWNTIME_REQ"
  MM_editColumn = "DOWN_REQ_ID"
  MM_recordId = "" + Request.Form("MM_recordId") + ""
  MM_editRedirectUrl = "default.asp"
  MM_fieldsStr  = "DOWN_REQ|value|REQ_FORM_ID|value"
  MM_columnsStr = "DOWN_REQ|',none,''|REQ_FORM_ID|none,none,NULL"

  ' create the MM_fields and MM_columns arrays
  MM_fields = Split(MM_fieldsStr, "|")
  MM_columns = Split(MM_columnsStr, "|")
  
  ' set the form values
  For i = LBound(MM_fields) To UBound(MM_fields) Step 2
    MM_fields(i+1) = CStr(Request.Form(MM_fields(i)))
  Next

  ' append the query string to the redirect URL
  If (MM_editRedirectUrl <> "" And Request.QueryString <> "") Then
    If (InStr(1, MM_editRedirectUrl, "?", vbTextCompare) = 0 And Request.QueryString <> "") Then
      MM_editRedirectUrl = MM_editRedirectUrl & "?" & Request.QueryString
    Else
      MM_editRedirectUrl = MM_editRedirectUrl & "&" & Request.QueryString
    End If
  End If

End If
%>
<%
' *** Update Record: construct a sql update statement and execute it

If (CStr(Request("MM_update")) <> "" And CStr(Request("MM_recordId")) <> "") Then

  ' create the sql update statement
  MM_editQuery = "update " & MM_editTable & " set "
  For i = LBound(MM_fields) To UBound(MM_fields) Step 2
    FormVal = MM_fields(i+1)
    MM_typeArray = Split(MM_columns(i+1),",")
    Delim = MM_typeArray(0)
    If (Delim = "none") Then Delim = ""
    AltVal = MM_typeArray(1)
    If (AltVal = "none") Then AltVal = ""
    EmptyVal = MM_typeArray(2)
    If (EmptyVal = "none") Then EmptyVal = ""
    If (FormVal = "") Then
      FormVal = EmptyVal
    Else
      If (AltVal <> "") Then
        FormVal = AltVal
      ElseIf (Delim = "'") Then  ' escape quotes
        FormVal = "'" & Replace(FormVal,"'","''") & "'"
      Else
        FormVal = Delim + FormVal + Delim
      End If
    End If
    If (i <> LBound(MM_fields)) Then
      MM_editQuery = MM_editQuery & ","
    End If
    MM_editQuery = MM_editQuery & MM_columns(i) & " = " & FormVal
  Next
  MM_editQuery = MM_editQuery & " where " & MM_editColumn & " = " & MM_recordId

  If (Not MM_abortEdit) Then
    ' execute the update
    Set MM_editCmd = Server.CreateObject("ADODB.Command")
    MM_editCmd.ActiveConnection = MM_editConnection
    MM_editCmd.CommandText = MM_editQuery
    MM_editCmd.Execute
    MM_editCmd.ActiveConnection.Close

    If (MM_editRedirectUrl <> "") Then
      Response.Redirect(MM_editRedirectUrl)
    End If
  End If

End If
%>
<%
Dim rsDownReq__MMColParam
rsDownReq__MMColParam = "1"
if (Request.QueryString("DOWN_REQ_ID") <> "") then rsDownReq__MMColParam = Request.QueryString("DOWN_REQ_ID")
%>
<%
set rsDownReq = Server.CreateObject("ADODB.Recordset")
rsDownReq.ActiveConnection = MM_labdict_STRING
rsDownReq.Source = "SELECT * FROM LABDICT_DOWNTIME_REQ WHERE DOWN_REQ_ID = " + Replace(rsDownReq__MMColParam, "'", "''") + ""
rsDownReq.CursorType = 0
rsDownReq.CursorLocation = 2
rsDownReq.LockType = 3
rsDownReq.Open()
rsDownReq_numRows = 0
%>
<%
set rsReqForm = Server.CreateObject("ADODB.Recordset")
rsReqForm.ActiveConnection = MM_labdict_STRING
rsReqForm.Source = "SELECT * FROM LABDICT_REQ_FORMS"
rsReqForm.CursorType = 0
rsReqForm.CursorLocation = 2
rsReqForm.LockType = 3
rsReqForm.Open()
rsReqForm_numRows = 0
%>
<html>
<head>
<title>edit downtime requisition</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="stylesheet" href="tables.css" type="text/css">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<table width="660" border="0" cellspacing="0" cellpadding="2" align="center">
  <tr> 
    <td align="center"><b><img src="images/Banner.jpg" width="660" height="108"></b></td>
  </tr>
  <tr> 
    <td>&nbsp;</td>
  </tr>
  <tr> 
    <td> 
      <div align="center"><b>Rewrite the requisition and choose 'update' to modify 
        the method option below</b></div>
    </td>
  </tr>
</table>
<form method="post" action="<%=MM_editAction%>" name="form1">
  <table align="center">
    <tr valign="baseline"> 
      <td nowrap align="right">downtime requisition:</td>
      <td> 
        <input type="text" name="DOWN_REQ" value="<%=(rsDownReq.Fields.Item("DOWN_REQ").Value)%>" size="32">
      </td>
    </tr>
    <tr valign="baseline"> 
      <td nowrap align="right">REQ_FORM_ID:</td>
      <td> 
        <select name="REQ_FORM_ID">
          <%
While (NOT rsReqForm.EOF)
%>
          <option value="<%=(rsReqForm.Fields.Item("REQ_FORM_ID").Value)%>" <%if (CStr(rsReqForm.Fields.Item("REQ_FORM_ID").Value) = CStr(rsDownReq.Fields.Item("REQ_FORM_ID").Value)) then Response.Write("SELECTED") : Response.Write("")%> ><%=(rsReqForm.Fields.Item("REQ_FORM_NUMBER").Value)%></option>
          <%
  rsReqForm.MoveNext()
Wend
If (rsReqForm.CursorType > 0) Then
  rsReqForm.MoveFirst
Else
  rsReqForm.Requery
End If
%>
        </select>
      </td>
    </tr>
    <tr valign="baseline"> 
      <td nowrap align="right">&nbsp;</td>
      <td> 
        <input type="submit" value="update">
      </td>
    </tr>
  </table>
  <input type="hidden" name="MM_update" value="true">
  <input type="hidden" name="MM_recordId" value="<%= rsDownReq.Fields.Item("DOWN_REQ_ID").Value %>">
</form>
<p>&nbsp;</p>
</body>
</html>
<%
rsDownReq.Close()
%>
<%
rsReqForm.Close()
%>

